package com.chuanjiabao.wisdom.util;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuanjiabao.wisdom.R;
import com.chuanjiabao.wisdom.ui.view.DropPopWindow;

import org.jetbrains.annotations.NotNull;

/**
 * 项目名称：chuanjiabao_android
 * 创建人：41614
 * 创建时间：2019-10-01 18:09
 */
public class DropPopWindowUtils {

    public static void showDrop(
            Context context,
            View anchor,
            String photoUrl,
            String videoUrl,
            String textUrl,
            String photoHint,
            String videoHint,
            String textHint,
            PopupWindowCallBack callBack
    ) {
        DropPopWindow drop = new DropPopWindow(context, R.layout.popu_layout_filter) {
            @Override
            public void afterInitView(@NotNull View view) {
                TextView tvAll = view.findViewById(R.id.tvModuleAll);
                ImageView ivPhoto = view.findViewById(R.id.ivModulePhoto);
                TextView tvPhoto = view.findViewById(R.id.tvModuleAllPhoto);
                ImageView ivVideo = view.findViewById(R.id.ivModuleVideo);
                TextView tvVideo = view.findViewById(R.id.tvModuleAllVideo);
                TextView ivText = view.findViewById(R.id.ivModuleText);
                TextView tvText = view.findViewById(R.id.tvModuleAllText);

                GlideUtil.setRoundUriMethod(
                        context,
                        photoUrl,
                        ivPhoto,
                        R.mipmap.icon_noimge,
                        0
                );
                GlideUtil.setRoundUriMethod(
                        context,
                        videoUrl,
                        ivVideo,
                        R.mipmap.icon_noimge,
                        0
                );
                ivText.setText(textUrl);
                tvPhoto.setText(photoHint);
                tvVideo.setText(videoHint);
                tvText.setText(textHint);

                tvAll.setOnClickListener(v -> {
                    dismiss();
                    callBack.onClick("0");
                });
                tvPhoto.setOnClickListener(v -> {
                    dismiss();
                    callBack.onClick("1");
                });
                tvVideo.setOnClickListener(v -> {
                    dismiss();
                    callBack.onClick("2");
                });
                tvText.setOnClickListener(v -> {
                    dismiss();
                    callBack.onClick("4");
                });
            }
        };
        drop.showAsDropDown(anchor);
    }

    public interface PopupWindowCallBack {
        void onClick(String type);
    }

}
